package com.yidu.t286.dao;

import com.yidu.t286.domain.Caruser;
import com.yidu.t286.domain.Vehicle;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*
 * @description:车辆信息表的接口类
 * @author:文杰
 * @date  :2021/7/27 0027上午 10:31
 */
@Mapper
public interface VehicleDao {

    /**
     * 向数据库表vehicle增加一行数据
     * @param vehicle 车辆信息对象
     * @return 影响的行数: 1:添加成功 2:添加失败
     */
    @Insert("insert into vehicle(vehicleId,brandId,vehiclePrice,licensingtime,mileage,emission,transfertimes," +
            "displacement,ownerships,transmission,bodycolor,productionDate,vehicleUrl) values(seq_vehicle.nextval,#{brandId}," +
            "#{vehiclePrice},#{licensingtime},#{mileage},#{emission},#{transfertimes},#{displacement},#{ownerships},#{transmission}," +
            "#{bodycolor},#{productionDate})")
    public int add(Vehicle vehicle);


    /**
     * 根据车辆信息id删除数据
     * @param vehicleId 车辆信息id
     * @return 影响的行数 1:删除成功 0:删除失败
     */
    @Delete("delete from vehicle where vehicleId=#{vehicleId}")
    public int delete(@Param("vehicleId") int vehicleId);


    /**
     * 在数据库表vehicle修改数据
     * @param vehicle 车辆信息对象
     * @return 影响的行数 1:修改成功 0:修改失败
     */
    @Update("update vehicle set brandId=#{brandId},vehiclePrice=#{vehiclePrice},licensingtime=#{licensingtime}" +
            ",mileage=#{mileage},emission=#{emission},transfertimes=#{transfertimes},displacement=#{displacement}," +
            "ownerships=#{ownerships},transmission=#{transmission},bodycolor=#{bodycolor},productionDate=#{productionDate}  where vehicleId=#{vehicleId}")
    public int update(Vehicle vehicle);


    /**
     * 从数据库表caruser查询所有数据
     * @return 用户对象
     */
    @Select("select * from vehicle")
    public List<Vehicle> findAll();

    /**
     * 按条件分页查询
     * @param start 开始的页数
     * @param rows 每页的行数
     * @param condition 条件字符串
     * @return 车辆信息对象集合
     */
    @Select("select * from(select a.*,rownum rn from (select * from vehicle where 1=1 ${condition}) a where rownum<#{rows}) where rn>#{start}")
    public List<Vehicle> findByPage(@Param("start") int start,@Param("rows") int rows,@Param("condition") String condition);

    /**
     * 多条件查询记录数
     * @param condition 条件字符串
     * @return 记录数
     */
    @Select("select count(*) from vehicle where 1=1 ${condition}")
    public int count(@Param("condition") String condition);

}
